package cn.lanqiao.rabc.controller;

import cn.lanqiao.rabc.entity.Message;
import cn.lanqiao.rabc.service.MessageService;
import cn.lanqiao.rabc.util.Result;
import static cn.lanqiao.rabc.util.Result.*;
import cn.lanqiao.rabc.vo.QueryMessageVO;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.Date;
import java.util.List;

/**
 * (Message)表控制层
 *
 * @author david
 * @since 2024-06-24 08:50:28
 */
@RestController
@RequestMapping("/message")
public class MessageController {
    /**
     * 服务对象
     */
    @Resource
    private MessageService messageService;

    /**
     * 通过主键查询单条数据
     *
     * @param queryMessageVO 主键
     * @return 单条数据
     */
    @PostMapping("/query")
    public ResponseEntity query(@RequestBody QueryMessageVO queryMessageVO) {
        PageHelper.startPage(queryMessageVO.getPageNum(),queryMessageVO.getPageSize());
        List<Message> messageList = messageService.queryAll(queryMessageVO);
        PageInfo<Message> pageInfo = new PageInfo<>(messageList);
        return success(pageInfo);
    }

    @PostMapping("/insert")
    public ResponseEntity query(@RequestBody Message message) {
        message.setCreateDate(new Date());
        return success(messageService.insert(message));
    }
}
